package com.xizi.factory.simple;


interface Computer {
    public void printComputer();
}

class MacbookProComputer implements Computer {
    public void printComputer() {
        System.out.println("这是一台 macbook pro");
    }
}

class SurfaceBookComputer implements Computer {
    public void printComputer() {
        System.out.println("这是一台 surface book");
    }
}

//
class ComputerFactory {
    public Computer createComputer(String type) {
        Computer c = null;
        if (type.equals("macbook")) {
            c = new MacbookProComputer();
        } else if (type.equals("surface")) {
            c = new SurfaceBookComputer();
        }
        return c;
    }
}

public class Client {

    public static void main(String[] args) {
        Client c = new Client();
        ComputerFactory cf = new ComputerFactory();
        //工厂创建一台macbook
        Computer computer = cf.createComputer("macbook");
        //客户进行购买
        c.buy(computer);
    }

    public void buy(Computer c) {
        System.out.println("我想要买一台电脑");
        c.printComputer();
    }
}
